﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MSysMonNET;
using System.Management;


namespace WinSysTester
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementScope scope = MSysCheckNetwork.getServerScope("[IP Address]", "[useraccount]", "[userpassword]");

            if (scope != null)
            {
                checkNetwork("127.0.0.1");
                //checkHTTP("[IP Address]", 80);
                //checkFTP("[IP Address]", 21);
                //checkDiskSpace(scope, "c:");
                //checkWebUsers(scope);
                //checkServerCPU(scope);
                //checkSQLdatabase("Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;");
                //checkOleDBdatabase("Provider=providerName;Password=myPassword;User ID=myUser;Data Source=myServer;Persist Security Info=True");
            }
            else
                Console.WriteLine("Not able to connect to remote server");

            Console.ReadKey();
        }

        static void checkNetwork(String hostName)
        {

            MSysCheckNetwork clsNetwork = new MSysCheckNetwork();
            long lngResult = clsNetwork.checkPing(hostName);

            if (lngResult >= 0)
                Console.WriteLine("Roundtrip time was: {0}", lngResult);
            else
                Console.WriteLine("Could not Ping!");
        }

        static void checkHTTP(String hostName, int portNumber)
        {

            MSysCheckServices clsServices = new MSysCheckServices();
            MSysServiceStatus clsReturn = clsServices.checkHTTPrunning(hostName, portNumber);

            if (clsReturn.serviceStatus)
                Console.WriteLine("HTTP Service is Up.");
            else
                Console.WriteLine("HTTP Service is Down or not present.");

            Console.WriteLine(clsReturn.returnMessage);
        }

        static void checkFTP(String hostName, int portNumber)
        {

            MSysCheckServices clsServices = new MSysCheckServices();
            MSysServiceStatus clsReturn = clsServices.checkFTPrunning(hostName, portNumber);

            if (clsReturn.serviceStatus)
                Console.WriteLine("FTP Service is Up.");
            else
                Console.WriteLine("FTP Service is Down or not present.");

            Console.WriteLine(clsReturn.returnMessage);
        }

        static void checkDiskSpace(ManagementScope scope, string driveLetter)
        {

            MSysCheckDisks clsDisks = new MSysCheckDisks();
            ulong result = clsDisks.checkDiskSpace(scope, driveLetter);

            Console.WriteLine("Space left on System Disk: {0}", result);
        }

        static void checkWebUsers(ManagementScope scope)
        {

            MSysCheckServerLoad clsWS = new MSysCheckServerLoad();
            uint result = clsWS.checkWebUsers(scope);

            Console.WriteLine("Users on Web Server: {0}", result);
        }

        static void checkServerCPU(ManagementScope scope)
        {

            MSysCheckServerLoad clsWS = new MSysCheckServerLoad();
            ulong result = clsWS.checkCPUload(scope);

            Console.WriteLine("CPU load on Server: {0}", result);
        }

        static void checkSQLdatabase(String connectionString)
        {

            MSysCheckDatabases clsDB = new MSysCheckDatabases();
            MSysServiceStatus clsReturn = clsDB.checkSQLServerConnection(connectionString);

            if (clsReturn.serviceStatus)
                Console.WriteLine("SQL Server is Up.");
            else
                Console.WriteLine("SQL Server is Down or not present.");

            Console.WriteLine(clsReturn.returnMessage);
        }

        static void checkOleDBdatabase(String connectionString)
        {

            MSysCheckDatabases clsDB = new MSysCheckDatabases();
            MSysServiceStatus clsReturn = clsDB.checkOleDBConnection(connectionString);

            if (clsReturn.serviceStatus)
                Console.WriteLine("Database Server is Up.");
            else
                Console.WriteLine("Database Server is Down or not present.");

            Console.WriteLine(clsReturn.returnMessage);
        }
    }
}
